/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2004
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
*
* Author's email : insane@dees.ufmg.br
* Author's Website : http://www.dees.ufmg.br/insane
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package br.ufmg.dees.insane.model.xfemModel.geometryDescription;

import java.util.ArrayList;
import java.util.List;

import br.ufmg.dees.insane.model.xfemModel.geometryEntity.GeometryEntity;
import br.ufmg.dees.insane.model.xfemModel.xfemElement.XFEMElement;
import br.ufmg.dees.insane.util.IPoint3d;
import br.ufmg.dees.insane.util.xfem.Segment;

/**
 * @author Kelson Wolff
 *
 */
public class StandardDescription extends GeometryDescription {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	public StandardDescription() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean interactsWith(XFEMElement e, GeometryEntity gE) {
		List<IPoint3d> pts = new ArrayList<IPoint3d>();
		
		for(int i=0; i<e.getNbNodes(); i++){
			double x = e.getIncidence().get(i).getX();
			double y = e.getIncidence().get(i).getY();
			double z = e.getIncidence().get(i).getZ();
			IPoint3d p = new IPoint3d(x,y,z);
			pts.add(p);
		}
		
		boolean ret = false;
		Segment s = null;
		for(int i=0; i<pts.size(); i++){
			if(i == (pts.size() - 1)){
				s = new Segment(pts.get(i),pts.get(0));
			}	
			else{
				s = new Segment(pts.get(i),pts.get(i+1));
			}
			if(gE.intersection(s).size() >= 1){
				ret = true;
				i = pts.size(); // no need to test more
			}	
		}
		return ret; 
	}

}
